package com.dubbo;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.utils.ReferenceConfigCache;
import com.alibaba.dubbo.rpc.service.GenericService;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author xiaolizhi
 * @date 2020/6/24
 */
public class TestDubbo2 {
 
    public static void main(String[] args) {
 
       //申明应用
        ApplicationConfig application = new ApplicationConfig();
        //提供方应用信息，用于计算依赖关系
        application.setName("kwg-dsp-asset");
        // 连接注册中心配置
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://127.0.0.1:2189");
 
        ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
        reference.setApplication(application);
        reference.setRegistry(registry);
        //接口名称
        reference.setInterface("com.kwggroupholdings.dsp.asset.api.PointQueryService");
        //版本
        reference.setVersion("1.0.1");
        //分组
//        reference.setGroup("scm");
        // 声明为泛化接口
        reference.setGeneric(true);
 
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        GenericService genericService = cache.get(reference);

        //POJO参数转换为MAP
        Map<String, Object> map = new HashMap<>();
        map.put("class","com.kwggroupholdings.dsp.asset.api.FindPointById");
        map.put("id","0000642b9795493fb676f496d16ca954");

        Object result = genericService.$invoke("findById",new String[]{"com.kwggroupholdings.dsp.asset.api.FindPointById"},new Object[]{map});
//        Object result =  genericService.$invoke("getDetailsByOrderCodeAndMaterialCode", new String[] { "java.lang.String" ,"java.lang.String" },objects);
        System.out.println("返回值=================================================:"+result);
    }
}